<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>注册页</title>
    <style>

        .ht{
            text-align: center;
            color: cadetblue;
            font-family: 幼圆;
        }
        .tab{
            width: 500px;
            border: 5px solid cadetblue;
            margin: 0px auto;
            border-radius: 5px;
            font-family: 幼圆;
        }
        .ltr td{
            border: 1px solid  powderblue;

        }
        .ipt{
            border: 0px;
            width: 50%;

        }
        .btn1{
            border: 2px solid powderblue;
            border-radius: 4px;
            width:60px;
            background-color: antiquewhite;

        }

        .msg {
            color: rgb(136, 209, 26);
        }

        .buttonContainer{
            text-align: center;
        }
    </style>
    <script>
        function checkUsername() {
            var usernameReg = /^[a-zA-Z0-9]{5,10}$/;
            var usernameInput = document.getElementById("usernameInput");
            var usernameMsg = document.getElementById("usernameMsg");
            if (!usernameReg.test(usernameInput.value)) {
                usernameMsg.innerText = "用户名格式错误";
                return false;
            }

            usernameMsg.innerText = "√";
            return true;
        }

        function checkUserPwd() {
            var userPwdReg = /^\d{6}$/; // 6 位数字
            var userPwdInput = document.getElementById("userPwdInput");
            var userPwdMsg = document.getElementById("userPwdMsg");
            if (!userPwdReg.test(userPwdInput.value)) {
                userPwdMsg.innerText = "密码必须是6位数字";
                return false;
            }

            userPwdMsg.innerText = "√";
            return true;
        }

        function checkReUserPwd() {
            var reUserPwdMsg = document.getElementById("reUserPwdMsg");
            if (!checkUserPwd()) {
                reUserPwdMsg.innerText = "密码格式错误";
                return false;
            }
            var userPwdInput = document.getElementById("userPwdInput");
            var reUserPwdInput = document.getElementById("reUserPwdInput");
            if (!(userPwdInput.value === reUserPwdInput.value)) {
                reUserPwdMsg.innerText = "两次密码不一致";
                return false;
            }
            reUserPwdMsg.innerText = "√";
            return true;
        }

        function checkForm() {
            var flag = checkUsername() && checkReUserPwd();
            if (!flag) {
                window.alert("注册失败"); // 提示用户
                // location.reload(); // 刷新页面
            }
            return flag;
        }

        function clearCheckMsg() {
            var usernameMsg =  document.getElementById("usernameMsg")
            var userPwdMsg =  document.getElementById("userPwdMsg")
            var reUserPwdMsg =  document.getElementById("reUserPwdMsg")
            usernameMsg.innerText  = userPwdMsg.innerText  = reUserPwdMsg.innerText = "";
        }
    </script>

</head>
<body>
<h1 class="ht">欢迎使用日程管理系统</h1>
<h3 class="ht">请注册</h3>
<form method="post" action="empty_page.html" onsubmit="return checkForm()" onreset="clearCheckMsg()">
    <table class="tab" cellspacing="0px">
        <tr class="ltr">
            <td>请输入账号</td>
            <td>
                <input class="ipt" id="usernameInput" type="text" name="username" onchange="checkUsername()">
                <span id="usernameMsg" class="msg"></span>
            </td>
        </tr>
        <tr class="ltr">
            <td>请输入密码</td>
            <td>
                <input class="ipt" id="userPwdInput" type="password" name="userPwd" onchange="checkUserPwd(), checkReUserPwd()">
                <span id="userPwdMsg" class="msg"></span>
            </td>
        </tr>
        <tr class="ltr">
            <td>确认密码</td>
            <td>
                <input class="ipt" id="reUserPwdInput" type="password" onchange="checkReUserPwd()">
                <span id="reUserPwdMsg" class="msg"></span>
            </td>
        </tr>
        <tr class="ltr">
            <td colspan="2" class="buttonContainer">
                <input class="btn1" type="submit" value="注册">
                <input class="btn1" type="reset" value="重置">
                <button class="btn1"><a  href="login.html">去登录</a></button>
            </td>
        </tr>
    </table>

</form>
</body>
</html>